﻿using ExcelDna.Integration.CustomUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace ExcelDNAForWPSDemo
{
    [ComVisible(true)]
    [ProgId("ExcelDNADemo")]
    [Guid("4A53D790-3744-4AC6-8340-2F566D3E1A9E")]
    public partial class Ribbon : ExcelRibbon
    {
        public static IRibbonUI RibbonUI;

        public void OnLoad(IRibbonUI ribbon)
        {
            RibbonUI = ribbon;//用公有变量获取到customUI
        }



        public override string GetCustomUI(string RibbonID)
        {
            return Util.GetTextContentsFromResource("Ribbon.xml");

        }



        public System.Drawing.Image GetRootImage(IRibbonControl control)
        {
            switch (control.Id)
            {
                case "btnOpenForm":
                    return Properties.Resources.窗体;
                case "btnCreateCustomTaskPane":
                    return Properties.Resources.任务窗格;
                default:
                    return null;
            }

        }

        public void btnOpenForm_Click(IRibbonControl control)
        {
            FormProduct form = new FormProduct();
            form.Show();
        }

        public void btnCreateCustomTaskPane_Click(IRibbonControl control)
        {
            try
            {
                var uscProduct = new UscProduct();
                var ctp = CustomTaskPaneFactory.CreateCustomTaskPane(uscProduct, "催化剂大家庭");
                ctp.DockPosition = MsoCTPDockPosition.msoCTPDockPositionRight;
                ctp.Width = 400;
                ctp.Visible = true;
            }
            catch (Exception ex)
            {

                Util.OutPutError(ex);
            }
        }
    }
}
